#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
'''
@File    :   mixins.py
@Time    :   2024/02/07 19:41:47
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib

from typing import Any
from django.db.models import QuerySet
from .models import Article


class ArticleViewMixin:
    request: Any
    
    def get_queryset(self) -> QuerySet:
        """
        获取查询集。如果当前请求的用户是超级用户，则返回所有对象的查询集，
        否则，返回当前请求用户拥有的所有对象的查询集。
        :return: 对象的查询集
        """
        if hasattr(self.context.request, "user") and self.context.request.user.is_superuser:
            return Article.objects.all()
        return Article.objects.filter(creator_id=self.context.request.user.id)